#include "ThumbnailHelper.h"

///Copyright (c) 2009-2010 T. Klepzig 

HTHUMBNAIL ThumbnailHelper::CreateThumbnail(HWND hWndDestination, HWND hWndSource, RECT rect)
{
	//RECT windowRect;

	//if (IsIconic(hWnd))
	//{
	//	//minimized
	//	WINDOWPLACEMENT wp={0};
	//	GetWindowPlacement(hWnd, &wp);

	//	if ((wp.flags & WPF_RESTORETOMAXIMIZED) == WPF_RESTORETOMAXIMIZED)
	//	{
	//		//minimized and maximized, when restored
	//		windowRect.left = wp.ptMaxPosition.x;
	//		windowRect.top = wp.ptMaxPosition.y;
	//		windowRect.right = windowRect.left + GetSystemMetrics(SM_CXMAXIMIZED);
	//		windowRect.bottom = windowRect.top + GetSystemMetrics(SM_CYMAXIMIZED);
	//	}
	//	else
	//	{
	//		//only minimized
	//		windowRect = wp.rcNormalPosition;
	//	}
	//}
	//else
	//{
	//	//normal window state
	//	GetWindowRect(hWnd, &windowRect);
	//}


	//windowRect.left += screenOffset.x;
	//windowRect.right += screenOffset.x;

	//windowRect.top += screenOffset.y;
	//windowRect.bottom += screenOffset.y;


	//windowRect.left += ScreenXOffset;
	//windowRect.right += ScreenXOffset;

	//windowRect.top += ScreenYOffset;
	//windowRect.bottom += ScreenYOffset;


	//windowRect.left = (int)(windowRect.left * FactorX);
	//windowRect.right = (int)(windowRect.right * FactorX);

	//windowRect.top = (int)(windowRect.top * FactorY);
	//windowRect.bottom = (int)(windowRect.bottom * FactorY);	


	//windowRect.left += rect.left;
	//windowRect.right += rect.left;

	//windowRect.top += rect.top;
	//windowRect.bottom += rect.top;

	HTHUMBNAIL hThumbnail = 0;

	if (!DwmRegisterThumbnail(hWndDestination, hWndSource, &hThumbnail))
	{
		DWM_THUMBNAIL_PROPERTIES thumbnailProperties={0};
		thumbnailProperties.dwFlags = DWM_TNP_SOURCECLIENTAREAONLY | DWM_TNP_VISIBLE | DWM_TNP_OPACITY | DWM_TNP_RECTDESTINATION;
		thumbnailProperties.fSourceClientAreaOnly = FALSE;
		thumbnailProperties.opacity = 255;
		thumbnailProperties.fVisible = true;
		thumbnailProperties.rcDestination = rect;

		DwmUpdateThumbnailProperties(hThumbnail, &thumbnailProperties);
	}

	return hThumbnail;
}

void ThumbnailHelper::DestroyThumbnail(HTHUMBNAIL hThumbnail)
{
	DwmUnregisterThumbnail(hThumbnail);
}
